#ifndef ZOOMLABEL_H
#define ZOOMLABEL_H

#include "common.h"
#include "point.h"
#include "namingdialog.h"

class ZoomLabel : public QLabel
{
    Q_OBJECT
signals:
    void clicked();
public:
    std::map<QPoint*,QString> tempPt;
    std::map<QString,Point*> *regionTmp;
    QPolygon poly;
    QImage *currImg;

    ZoomLabel();
    void setTemp(std::map<QString,Point*> t);
    std::map<QString,Point*> getTemp();
    void setPixmap(const QPixmap &p);
    double getRotateFactor();
    double getScaleFactor();
    void setScaleFactor(double factor);
    void setRotateFactor(double factor);
    void setOrigPicSize(QSize picSize);
    QSize getOrigPicSize();
    void setMode(int mode);
    void setStatus(int status);
    int getMode();
    int getStatus();
    bool getEditStatus();
    void setEditStatus(bool status);
    QImage getPic();
    void setPic(QImage img);
    QPixmap getPmap();
    void setPmap(QPixmap map);
    QPoint getPicOffset();
    void setPicOffset(QPoint off);
    QPoint getPolyOffset();
    void setPolyOffset(QPoint off);
    QSize getRealPicSize();
    void setRealPicSize(QSize s);
    QPoint getCenterPos();
    void setCenterPos(QPoint pos);
    QPoint getMousePos();
    //QSize getPicSize();
    void setPixel(int x,int y,uint rgb);
    void reRender();
    void refresh();
    QImage Crop(QImage srcImg,QPolygon sect);
protected:
    void wheelEvent(QWheelEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void paintEvent(QPaintEvent *event) override;
    void scaleImage(QPixmap &p,double scaleFactor,bool inner);
    QImage rotateImage(QImage *img,QPoint center,double rotateFactor,QPoint imgOffset = QPoint(0,0));
    void keyPressEvent(QKeyEvent *event) override;
private:
    double pi = 3.1415926535;
    double rotateAng;
    double rotateFactor;
    double scaleFactor;
    const double scaleStep = 1.15;

    QSize realPicSize;
    QSize origPicSize;
    QPoint origPicCenter;
    QPoint lastPoint;
    QPoint imgOffset;
    QPoint polyOffset;
    QPoint offset;
    QPoint lastRotatePoint;
    QPoint currMousePos;
    QPoint centerPos;

    bool isRotating;
    bool isDragging;
    bool isCompleteEdit;

    QImage *pic;
    QPixmap *pmap;


    //0-观察模式,1-修改模式
    int mode;

    //0-平移,1-旋转
    int status = 0;


    std::map<QString,Point*>* tmp;

};

#endif // ZOOMLABEL_H
